//
//  XDVideoPlayViewController.m
//  XDEducation
//
//  Created by apple on 2017/4/21.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDVideoPlayViewController.h"
#import "AppDelegate.h"
#import "JWPlayer.h"
#import "XDVideoModel.h"
@interface XDVideoPlayViewController ()

/** 播放视图 */
@property(nonatomic,strong) JWPlayer *player ;
@end

@implementation XDVideoPlayViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    //9*414/16
    _player= [[JWPlayer alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height/2.5)];
    _player.vc = self;
    [_player updatePlayerWith:[NSURL URLWithString:self.videoModel.absoluteUrl]];
    [self.view addSubview:_player];
    
    
    
    
    [self initUI];
    
}

-(void)initUI{
    

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"正常播放: %@",self.videoModel.title]];
    
    [str addAttribute:NSForegroundColorAttributeName
                value:ThemeColor
                range:NSMakeRange(0,5)];
    [str addAttribute:NSForegroundColorAttributeName
                value:UIColorFromRGB(0x808080)
                range:NSMakeRange(6,str.length-6)];
    
    
    UILabel *title = [[UILabel alloc]init];
    title.attributedText = str;
    title.font = [UIFont systemFontOfSize:17];
 
    [self.view addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.top.equalTo(self.player.mas_bottom).offset(20);
        make.right.equalTo(self.view.mas_right).offset(-15);
    }];
    
    
    
    if (self.videoModel.videoDesc.length!=0) {
        
        NSMutableAttributedString *strDesc = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"视频描述: %@",self.videoModel.videoDesc]];
        
        [strDesc addAttribute:NSForegroundColorAttributeName
                    value:ThemeColor
                    range:NSMakeRange(0,5)];
        [strDesc addAttribute:NSForegroundColorAttributeName
                    value:UIColorFromRGB(0x808080)
                    range:NSMakeRange(6,strDesc.length-6)];
        
        UILabel *desc = [[UILabel alloc]init];
        desc.attributedText = strDesc;
        desc.font = [UIFont systemFontOfSize:17];
        desc.numberOfLines = 0;
        [self.view addSubview:desc];
        
        [desc mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(15);
            make.top.equalTo(title.mas_bottom).offset(20);
            make.right.equalTo(self.view.mas_right).offset(-15);
        }];

    }
    
}

-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [_player removeFromSuperview];

}

-(void)dealloc{
    NSLog(@"%s",__func__);
    
}

@end
